import java.util.*;

/**
 * @author LKQ
 * @date 2022/3/23 20:38
 * @description
 */
public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] co = {4, -1, 4, -2, 4};
        int[][] ob = {{2,4}};
        solution.robotSim(co, ob);
    }

    public int robotSim(int[] commands, int[][] obstacles) {
        // 面向北方
        int turn = 0, x = 0, y = 0;
        // 四个方向坐标变化 北，东，南，西
        int[][] dirs = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
        // 字符串作为障碍物检测，
        Set<String> set = new HashSet<>();
        for (int[] o : obstacles) {
            set.add(o[0] + "," + o[1]);
        }
        int max = 0;
        for (int command : commands) {
            if (command == -2) {
                turn = (turn + 3) % 4;
            } else if (command == -1) {
                turn = (turn + 1) % 4;
            } else {
                for (int i = 0; i < command; i++) {
                    int nx = x + dirs[turn][0], ny = y + dirs[turn][1];
                    String location = nx + "," + ny;
                    if (!set.contains(location)) {
                        x = nx;
                        y = ny;
                        max = Math.max(max, x * x + y * y);
                    }else {
                        break;
                    }
                }
            }
        }
        return max;
    }
}
